<?php
namespace app\api\controller;
use think\Request;
use app\api\controller\Base;
use app\api\model\UserCart as MuserCart;

/**
 * @title cart 购物车商品接口|[客户端]
 * @description 与购物车有关的信息
 */
 
class UserCart extends Base
{
    /**
     * @title cart/list 查询购物车商品列表信息 GET
     * @description 说明：依据 user_id 查询购物车商品列表信息 
     * @author 虾哥@2424899422@qq.com
     * @url cart/list/
	 * @Turl api/user_cart/lists
	 
	 * @param name:user_id type:int require:1 default:null other: desc:用户ID
	 * @param name:page type:int require:0 default:1 other: desc:当前页ID
	 * @param name:length type:int require:0 default:5 other: desc:当前页显示数量
	 *
	 * @return lists:购物车列表|参考备注信息@
     * @lists cart_id:收货地址自增ID  goods_name:商品名称 is_check:是否选中 goods_count:商品数量 goods_thums:商品缩略图   goods_desc:商品描述 shop_price:商品价格 count_money:单类型商品价格(商品数量*商品价格) 
	 * @return total_money:选中商品总价格
	 *
	 * @remark 返回示例{"code":0,"message":"query cart list success !","data":{"list":[{"cart_id":2,"is_check":1,"goods_count":3,"goods_name":"ed","goods_thums":"ere","goods_desc":"","shop_price":"3.00","count_money":9},{"cart_id":3,"is_check":1,"goods_count":2,"goods_name":"de","goods_thums":"efe","goods_desc":"","shop_price":"3.00","count_money":6},{"cart_id":4,"is_check":1,"goods_count":2,"goods_name":"de","goods_thums":"efe","goods_desc":"","shop_price":"3.00","count_money":6}],"total_money":21}}
     */
    public function lists($user_id,$page,$length)
    {
		$return = array('code' => 0, 'message' => 'query cart list success !', 'data' => array());
		$data = MuserCart::lists($user_id,$page,$length);
		if (empty($data)) {
            $return['code'] = 1;
            $return['message'] = 'query cart list failed !';
            return $return;
        }
        $return['data'] = $data;
		return json($return);	
    }
	
	
	/**
     * @title cart/create 添加商品到购物车 POST
     * @description 说明：依据 user_id 添加商品到购物车 |【暂不支持批量添加】
	 * @author 虾哥@2424899422@qq.com
	 * @url cart/create/
	 * @Turl api/user_cart/create
	 
	 * @param name:user_id type:int require:1 default:null other: desc: 用户ID
	 * @param name:good_ids type:int require:1 default:null other: desc:商品ID
	 * @param name:is_check type:int require:1 default:1 other: desc:是否选中
	 * @param name:goods_count type:int require:1 default:1 other: desc:商品数量
	 * @param name:goods_attr_id type:int require:1 default:0 other: desc:商品属性ID

	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为新增行数
     * 
     */
    public function create() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'create cart success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = MuserCart::cartAdd($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'create cart failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
	}
	
	/**
     * @title cart/delete 删除购物车商品 GET
     * @description 依据 address_ids 删除购物车商品 | 【暂不支持批量删除】| 支持清空购物车
	 * @author 虾哥@2424899422@qq.com
	 * @url cart/delete/
	 * @Turl api/user_cart/delete
	 
	 * @param name:user_id type:int require:1 default:null other: desc: 用户ID
	 * @param name:cart_id type:int require:1 default:null other: desc:收货地址自增ID集合
	 * @param name:is_all_clear type:int require:0 default:0 other: desc:是否清空|0否/1是|默认为0 
	 
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为删除行数
     *
     */
    public function delete($cart_id,$user_id,$is_all_clear) {
        $return = array('code' => 0, 'message' => 'delete cart success !', 'data' => array());
		$data = MuserCart::cartDelete($cart_id,$user_id,$is_all_clear);
		if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'delete cart failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
    }
	
	
	/**
     * @title cart/update 更新购物车商品相关信息 POST
     * @description 依据 cart_id 更新购物车商品相关信息 
	 * @author 虾哥@2424899422@qq.com
	 * @url cart/update/
	 * @Turl api/user_cart/update
  
	 * @param name:user_id type:int require:1 default:null other: desc: 用户ID
	 * @param name:good_ids type:int require:1 default:null other: desc:商品ID
	 * @param name:is_check type:int require:1 default:1 other: desc:是否选中
	 * @param name:goods_count type:int require:1 default:1 other: desc:商品数量
	 * @param name:goods_attr_id type:int require:1 default:0 other: desc:商品属性ID

	 
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为更新行数
     */

    public function update() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'update cart success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = MuserCart::cartUpdate($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'update cart failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	 
    }


	 /**
     * @title cart/2order 更新购物车商品相关信息 POST
     * @description 依据 cart_id 更新购物车商品相关信息 
	 * @author 虾哥@2424899422@qq.com
	 * @url cart/update/
	 * @Turl api/user_cart/lists
  
	 * @param name:user_id type:int require:1 default:null other: desc: 用户ID
	 * @param name:good_ids type:int require:1 default:null other: desc:商品ID
	 * @param name:is_check type:int require:1 default:1 other: desc:是否选中
	 * @param name:goods_count type:int require:1 default:1 other: desc:商品数量
	 * @param name:goods_attr_id type:int require:1 default:0 other: desc:商品属性ID

	 
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为更新行数
     */
	
	/**
	支付方式	pay_id	是	Int	5	支付方式	1.3.0	
	运输方式	shipping_id		Int	3	运输方式	1.3.0	
	购物车id	rec_id	Int	是	4	购物车id	1.3.0	
	收货地址id	address_id	Int	是	0	默认为0，0为默认地址	1.3.0	
	积分	integral	Int	是		积分	1.3.0	
	发票类型	inv_type	string	是		发票类型	1.3.0	
	发票抬头	inv_payee	string	是		发票抬头	1.3.0	
	发票内容	inv_content	string	是		发票内容	1.3.0	
	发票纳税人识别码	inv_tax_no	string	是	门店和小程序时新增	发票纳税人识别码	1.7.0	
	发票抬头类型	inv_title_type
	
	
	
    public function done() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'update cart success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = MuserCart::cartUpdate($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'update cart failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	 
    }
	*/

}
